/*
 * Copyright (C) 2011 Johan Kannala
 *
 * Licensed under the MIT License. You can find a copy of the License at in the
 * license.txt file.
 */
package com.joppe.vocabtutor;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.*;
import android.widget.EditText;

/**
 * @author joppe
 *
 */
public class CreateBookActivity extends LoggedActivity {
    private VocabTutor mApplication = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mApplication = (VocabTutor) this.getApplication();
        requestWindowFeature(Window.FEATURE_LEFT_ICON);
        setContentView(R.layout.createbook_activity);
        getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
            android.R.drawable.ic_dialog_alert);
    }
    
    public void createBook(View button) {
        EditText bookName = (EditText) findViewById(R.id.createbook_name_fld);
        Log.i("event_notification", "New book created: "
                + bookName.getText().toString());
        SQLiteDatabase db = null;
        try {
            db = mApplication.getDataHelper().getWritableDatabase();
            ContentValues content = new ContentValues();
            content.put("title", bookName.getText().toString());
            db.insert("books", null, content);
            finish();
        }
        catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
